package com.beilang.hotline.issue.page;

import com.beilang.base.codelookup.manager.CodeLookupMgr;
import com.beilang.base.core.page.BasePage;
import com.beilang.base.pagination.PaginationHelper;
import com.beilang.base.util.CodeConstant;
import com.beilang.base.util.DateUtil;
import com.beilang.hotline.issue.manager.IssueMgr;
import com.beilang.hotline.issue.model.IssueModel;
import com.beilang.hotline.issue.to.SearchTO;
import com.beilang.hotline.user.model.UserModel;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@SuppressWarnings("unchecked")
public class IssuePage extends BasePage{
	
	private CodeLookupMgr codeLookupMgr;
	
	private IssueMgr issueMgr;
	
	public void setIssueMgr(IssueMgr issueMgr) {
		this.issueMgr = issueMgr;
	}

	public void setCodeLookupMgr(CodeLookupMgr codeLookupMgr) {
		this.codeLookupMgr = codeLookupMgr;
	}
	
	public List getSysList(){
		List list=new ArrayList();       
		list.add(this.getEmptyIntCodeModel());
		list.addAll(getAddSysList());
		return list;
	}

	public List getAddSysList(){
		 return codeLookupMgr.getCodeListWithFilter(CodeConstant.SYS_NAME, CodeConstant.CODE_FILTER, new ArrayList());
	}

	public List getUpdateSysList(){
		 return getAddSysList();
	}    

    public PaginationHelper getSearchList(PaginationHelper helper,SearchTO searchTO){
		helper=issueMgr.getIssueList(helper, searchTO);
		return helper;
	}
	
	public PaginationHelper deleteIssueList(PaginationHelper helper,SearchTO searchTO,List deleteList){
        for (Object obj : deleteList) {
            IssueModel issueModel = (IssueModel) obj;
            issueMgr.deleteIssue(issueModel.getIssueId());
        }
		return this.getSearchList(helper, searchTO);
	}	
	
	public IssueModel addIssue(IssueModel issueModel){
		UserModel user=this.getLoginUser();
		issueModel.setCreateId(user.getUserId());
		issueModel.setUpdateId(user.getUserId());
		Date date = DateUtil.getDate();
		issueModel.setCreateTime(date);
		issueModel.setUpdateTime(date);		
		issueModel=issueMgr.createIssue(issueModel);
		return issueModel;
	}
	
	public IssueModel getViewIssue(Long issueId){
		return issueMgr.getIssue(issueId);
	}
	
	public IssueModel getUpdateIssue(Long issueId){
		return getViewIssue(issueId);
	}
	
	public IssueModel updateIssue(IssueModel issueModel){
		UserModel user=this.getLoginUser();
		issueModel.setUpdateId(user.getUserId());
		Date date = DateUtil.getDate();
		issueModel.setUpdateTime(date);		
		issueModel=issueMgr.saveIssue(issueModel);
		return issueModel;
	}
	


}
